class FormatStringTagLib {

    def stringFormat = {
        attrs,body ->

        def limit 
        def lineLimit
        
        if(attrs.limit)
        try{
            limit = Integer.parseInt(attrs.limit)
        }catch(e){
            log.warn("不合法的总字数 limit ： "+attrs.limit)
        }

        if(attrs.lineLimit)
        try{
            lineLimit = Integer.parseInt(attrs.lineLimit)
        }catch(e){
            log.warn("不合法的每行字数 lineLimit ："+attrs.lineLimit)
        }

        def result=body()
        if(limit){
            result=result.length()<limit ? result :result.substring(0,limit-2)+"..."
        }

        if(lineLimit){
            def tr=''
            for(int i=0;i<result.length();i++){
                tr+=result.charAt(i)
                if((i+1)%lineLimit==0) tr+="<br/>"
            }
            result = tr
        }

        out << result
    }
}
